package com.zlt.healthpass.controller;

import com.zlt.healthpass.bean.*;
import com.zlt.healthpass.service.IUserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

//声明它是一个接口
@Api(tags = "健康通信息获取接口")
@Controller
public class ScanQRCodeController {

    //和业务逻辑层进行关联
    @Autowired
    private IUserInfoService iis;

    @ApiOperation(value = "获取hello信息", notes = "测试用的，没有什么意义")
    //Get请求
    @GetMapping("/hello")
    //直接返回主体内容
    @ResponseBody
    public String helloWorld(){
        return "Hello World";
    }

    @ApiOperation(value = "获取姓名和身份证", notes = "传入昵称获取")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "nickName", value = "昵称", paramType = "query", example = "张三", required = true),
            }
    )
    @GetMapping("/getUserInfo")
    @ResponseBody
    public UserInfo getUserInfo(String nickName){
        //alt + shift + L
        //ctrl + 1
        //实例化类 得到对象
        /*UserInfo userInfo = new UserInfo();*/
        //设置对象的属性值
        /*userInfo.setName("李*");
        userInfo.setIdCard("510*************12");*/
        //响应结果
        UserInfo userInfo = iis.selectUserInfoByNickname(nickName);
        return userInfo;
    }

    @ApiOperation(value = "获取用户二维码状态", notes = "传入昵称获取")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "nickName", value = "昵称", paramType = "query", example = "张三", required = true),
            }
    )
    @GetMapping("/getUserHealthStatus")
    @ResponseBody
    public Info getUserHealthStatus(String nickName){
        int i = iis.selectHealthStatusByNickname(nickName);
        Info info = new Info(200, "成功了", i);
        return info;
    }


    @ApiOperation(value = "提交扫码信息的接口", notes = "传入id和场所信息")
    @PostMapping("/postLocationCode")
    @ResponseBody
    public int postLocationCode(@RequestBody Localtion localtion){
        //获取当前系统时间
        localtion.setDate(new Date());
        //调用业务逻辑之前
        int i = iis.insertLocaltionCode(localtion);
        return i;
    }


    @ApiOperation(value = "获取核酸检测报告接口", notes = "传入id获取")
    @GetMapping("/getNucleicAcidTest")
    @ResponseBody
    public NucleicAcidTest getNucleicAcidTest(int userId){
        NucleicAcidTest nucleicAcidTest = iis.selectTestByUserId(userId);
        return nucleicAcidTest;
    }


    @ApiOperation(value = "提交用户经纬度", notes = "提交用户经纬度")
    @PostMapping("/postLocationMsg")
    @ResponseBody
    public int postLocationMsg(@RequestBody LocationMsg lm){
        //获取当前系统时间
        lm.setCreateTime(new Date());
        //调用业务逻辑之前
        int i = iis.insertLocationMsg(lm);
        return i;
    }
}
